Enter Student Results
Enter New Result
You can only enter results for your assigned classes and subjects.
Grading System
| Score Range | Grade | Remark |
|---|---|---|
| 70 - 100 | A | Excellent |
| 60 - 69 | B | Very Good |
| 50 - 59 | C | Good |
| 45 - 49 | D | Pass |
| 40 - 44 | E | Fair |
| 0 - 39 | F | Fail |
prepare($sql); $stmt->execute([':staff_id' => $staff_id]); $staff = $stmt->fetch(PDO::FETCH_ASSOC); $assigned_classes = explode(',', $staff['classes']); $assigned_subjects = explode(',', $staff['subjects']); // Get class names $class_placeholders = str_repeat('?,', count($assigned_classes) - 1) . '?'; $sql_classes = "SELECT sn, classid FROM class WHERE sn IN ($class_placeholders) ORDER BY classid"; $stmt_classes = $DBcon->prepare($sql_classes); $stmt_classes->execute($assigned_classes); $classes = $stmt_classes->fetchAll(PDO::FETCH_ASSOC); // Get subject names $subject_placeholders = str_repeat('?,', count($assigned_subjects) - 1) . '?'; $sql_subjects = "SELECT subject_id, subjectname FROM subjectss WHERE subject_id IN ($subject_placeholders) ORDER BY subjectname"; $stmt_subjects = $DBcon->prepare($sql_subjects); $stmt_subjects->execute($assigned_subjects); $subjects = $stmt_subjects->fetchAll(PDO::FETCH_ASSOC); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_result'])) { $class_id = sanitize_input($_POST['class_id']); $subject_id = sanitize_input($_POST['subject_id']); $student_name = sanitize_input($_POST['student_name']); $student_id = sanitize_input($_POST['student_id']); $ca_score = floatval($_POST['ca_score']); $exam_score = floatval($_POST['exam_score']); $total_score = $ca_score + $exam_score; $term = sanitize_input($_POST['term']); $session_year = sanitize_input($_POST['session_year']); // Validate inputs if (!in_array($class_id, $assigned_classes)) { $message = 'You are not assigned to teach this class'; $message_type = 'danger'; } elseif (!in_array($subject_id, $assigned_subjects)) { $message = 'You are not assigned to teach this subject'; $message_type = 'danger'; } elseif ($ca_score < 0 || $ca_score > 30) { $message = 'CA score must be between 0 and 30'; $message_type = 'danger'; } elseif ($exam_score < 0 || $exam_score > 70) { $message = 'Exam score must be between 0 and 70'; $message_type = 'danger'; } else { // Check if results table exists, create if not $check_table = "CREATE TABLE IF NOT EXISTS student_results ( result_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, student_id VARCHAR(50) NOT NULL, student_name VARCHAR(100) NOT NULL, class_id INT(10) NOT NULL, subject_id INT(10) NOT NULL, ca_score DECIMAL(5,2) NOT NULL, exam_score DECIMAL(5,2) NOT NULL, total_score DECIMAL(5,2) NOT NULL, term VARCHAR(20) NOT NULL, session_year VARCHAR(10) NOT NULL, teacher_id INT(10) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (result_id), INDEX idx_student (student_id), INDEX idx_class (class_id), INDEX idx_subject (subject_id), INDEX idx_teacher (teacher_id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1"; $DBcon->exec($check_table); // Insert result $sql = "INSERT INTO student_results (student_id, student_name, class_id, subject_id, ca_score, exam_score, total_score, term, session_year, teacher_id) VALUES (:student_id, :student_name, :class_id, :subject_id, :ca_score, :exam_score, :total_score, :term, :session_year, :teacher_id)"; $stmt = $DBcon->prepare($sql); $result = $stmt->execute([ ':student_id' => $student_id, ':student_name' => $student_name, ':class_id' => $class_id, ':subject_id' => $subject_id, ':ca_score' => $ca_score, ':exam_score' => $exam_score, ':total_score' => $total_score, ':term' => $term, ':session_year' => $session_year, ':teacher_id' => $staff_id ]); if ($result) { $message = 'Result saved successfully!'; $message_type = 'success'; // Clear form $_POST = []; } else { $message = 'Failed to save result. Please try again.'; $message_type = 'danger'; } } } ?>
You can only enter results for your assigned classes and subjects.
| Score Range | Grade | Remark |
|---|---|---|
| 70 - 100 | A | Excellent |
| 60 - 69 | B | Very Good |
| 50 - 59 | C | Good |
| 45 - 49 | D | Pass |
| 40 - 44 | E | Fair |
| 0 - 39 | F | Fail |